package com.cn.aam.checaiduo.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * @author 艹羊
 * @project Checaiduo_Android
 * @date 2017/6/22 上午11:17
 * @description
 */

public class TimeUtils {


    public final static String DATE_FORMAT_TYPE_01 = "yyyy-MM-dd HH:mm:ss";
    public final static String DATE_FORMAT_TYPE_02 = "MM月dd日 HH:mm";

    /**
     * String转Date
     */
    public static Date String2Date(String str, String format) {
        SimpleDateFormat df1 = new SimpleDateFormat(format, Locale.CHINA);
        Date date = null;
        try {
            date = df1.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    /**
     * Date转String
     */
    public static String Date2String(Date date, String format) {
        SimpleDateFormat df1 = new SimpleDateFormat(format, Locale.CHINA);
        return df1.format(date);
    }


    /**
     * 显示倒计时
     */
    public static String formatSecondTime(long seconds) {
        long day = seconds / (24 * 60 * 60);
        seconds = seconds % (24 * 60 * 60);
        long hour = seconds / (60 * 60);
        seconds = seconds % (60 * 60);
        long minute = seconds / 60;
        long second = seconds % 60;
        StringBuilder sb = new StringBuilder();
        if (day > 0)
            sb.append(day + "天");
        sb.append(hour + "小时");
        sb.append(minute + "分");
        sb.append(second + "秒");
        return sb.toString();
    }

}
